#from django.db import models
from django.contrib.auth.models import User
from django.contrib.gis.db import models

# Create your models here.
# need to add meta(field descriptions) for all fields to provide definitions to user

class Edibility(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(blank=True)
    def __unicode__(self):
        return self.name

class Season(models.Model):
    start_date = models.DateField()
    end_date = models.DateField()
    def __unicode__(self):
        return self.start_date.strftime("%B") + " - " + self.end_date.strftime("%B")

class EdibleType(models.Model):
    common_name = models.CharField(max_length=200)
    formal_name = models.CharField(max_length=200,blank=True)
    edibility = models.ForeignKey(Edibility)
    # region / Climate zone.
    season_info = models.ManyToManyField(Season,blank=True)
    photo = models.ImageField(upload_to="ue_photos",blank=True)
    ident_info = models.CharField(max_length=2*1024,blank=True)
    harvesting_info = models.CharField(max_length=2*1024,blank=True)
    prep_info = models.CharField(max_length=2*1024,blank=True)
    preserving_info = models.CharField(max_length=2*1024,blank=True)
    med_use = models.CharField(max_length=2*1024,blank=True)
    warnings = models.CharField(max_length=1*1024,blank=True)
    #
    def __unicode__(self):
        return self.common_name

class Edible(models.Model):
    user = models.ForeignKey(User)
    edible_type = models.ForeignKey(EdibleType)
    chemSprayDate = models.DateField(null=True, blank=True)
    local_risks = models.CharField(max_length = 1*1024, null=True, blank=True)
    time_stamp = models.TimeField(auto_now=True, editable=False)
    location = models.PointField(blank=True)
    objects = models.GeoManager()

    def __unicode__(self):
        return "%s" %self.edible_type.common_name
                              

class Comment (models.Model):
    user = models.ForeignKey(User)
    time_stamp = models.TimeField(auto_now=True)
    comment = models.CharField(max_length=2*1024)
    edible = models.ForeignKey(Edible)
    rating = models.IntegerField()
    def __unicode__(self):
        return str(self.user) + " : " + self.comment


class EdiblePhoto (models.Model):
    photo = models.ImageField(upload_to="ue_photos",blank=True)
    submitter = models.ForeignKey(User)
    caption = models.CharField(max_length=128)
    time_stamp = models.TimeField(auto_now=True)
    edible = models.ForeignKey(Edible)
    def __unicode__(self):
        return self.caption

class CommentPhoto (models.Model):
    comment = models.ForeignKey(Comment)
    submitter = models.ForeignKey(User)
    caption = models.CharField(max_length=128)
    photo = models.ImageField(upload_to="ue_photos",blank=True)
    time_stamp = models.TimeField(auto_now=True)
    def __unicode__(self):
        return self.caption

# plan to refacter to use inheritance of common fields all around!
# we shouldn't repeat so much to defined all 3 different photo types.

class Recipe(models.Model):
    name = models.CharField(max_length=128)
    # (EdibleType, amount) tuple list of foreign keys
    instructions = models.CharField(max_length=8*1024)
    photo = models.ImageField(upload_to="ue_photos",blank=True)
    def __unicode__(self):
        return self.name

class RecipeComment (models.Model):
    submitter = models.ForeignKey(User)
    time_stamp = models.TimeField(auto_now=True)
    comment = models.CharField(max_length=2*1024)
    recipe = models.ForeignKey(Recipe)
    rating = models.IntegerField()
    url = models.URLField()
    def __unicode__(self):
        return str(self.recipe)


class RecipePhoto (models.Model):
    photo = models.ImageField(upload_to="ue_photos",blank=True)
    submitter = models.ForeignKey(User)
    recipe = models.ForeignKey(Recipe)
    caption = models.CharField(max_length=128)
    def __unicode__(self):
        return self.caption



  
